Connectivity Software development products are primarily written in Microsoft .NET, and PowerShell is natively a .NET development language and enviroment. Therefore, in principle, .NET-related descriptions in this documentation set apply to PowerShell as well, and PowerShell programs are created in the same way as C# or VB.NET programs. There are, however, some slight differences to be aware of.
In PowerShell, use the Add-Type cmdlet to make Connectivity Software classes available in your PowerShell session. You need to specify a full path to Connectivity Software assemblies, and the assembly name that you want to use.
QuickOPC Example
OPC Wizard Example
PowerShell has some special requirements when its code is called (as a callback) from the components you use in your PowerShell script. If the callback is made from a thread that is different from the script thread, an error like "There is no Runspace available to run scripts in this thread. …" can occur internally. In many cases, the error will be handled internally, and to you, it will appear as if the callback had not been called at all.
In order to overcome this issue, you can use the function [RunspacedDelegateFactory]::NewRunspacedDelegate to wrap your PowerShell callback. This function is contained in the OpcLabs.PowerShellManagement assembly that you references using the Add-Type cmdlet. This technique is illustrated throughout our example wherever it is necessary, so you can learn the precise syntax from there.